home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / performAttachCrv.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  14.2 KB  |  521 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  11 April 1997
  22. //  Author:         mgr
  23. //
  24. //  Description:
  25. //        Initialize the option values for attach menu item.
  26. //
  27. //  Input Arguments:
  28. //      int action
  29. //          0 - just execute the attach operation
  30. //        1 - show the option box dialog
  31. //          2 - drag to shelf
  32. //
  33. //  Return Value:
  34. //      None.
  35. //
  36.  
  37. proc setOptionVars(int $forceFactorySettings)
  38. {
  39.     //    Keep multiple knots (on-1 or off-0 to be used if attach is on).
  40.     //
  41.     if ($forceFactorySettings || !`optionVar -exists attachCrvKeepMultKnots`) {
  42.         optionVar -intValue attachCrvKeepMultKnots 1;
  43.     }
  44.  
  45.     // keep original (for in place operations is on-1 or off-0).
  46.     //
  47.     if ($forceFactorySettings || !`optionVar -exists attachCrvKeepOriginal`) {
  48.         optionVar -intValue attachCrvKeepOriginal 1;
  49.     }
  50.  
  51.     // blend method
  52.     //
  53.     if ($forceFactorySettings || !`optionVar -exists attachCrvMethod`) {
  54.         optionVar -intValue attachCrvMethod 1;
  55.     }
  56.  
  57.     // insert knots for blend
  58.     //
  59.     if ($forceFactorySettings || !`optionVar -exists attachCrvBlendInsert`) {
  60.         optionVar -intValue attachCrvBlendInsert 0;
  61.     }
  62.  
  63.     // blend bias
  64.     //
  65.     if ($forceFactorySettings || !`optionVar -exists attachCrvBlendBias`) {
  66.         optionVar -floatValue attachCrvBlendBias 0.5;
  67.     }
  68.  
  69.     // blend insert
  70.     //
  71.     if ($forceFactorySettings || !`optionVar -exists attachCrvBlendParameter`) {
  72.         optionVar -floatValue attachCrvBlendParameter 0.1;
  73.     }
  74. }
  75.  
  76. global proc attachCrvVisibility( string $parent, int $method,
  77.                                  int $insert )
  78. {
  79.     if( $method < 0 ) {
  80.         $method = `radioButtonGrp -q -sl attachCrvMethodWidget` - 1;
  81.     }
  82.     if( $insert < 0 ) {
  83.         $insert = `checkBoxGrp -q -v1 attachCrvBlendInsertWidget`;
  84.     }
  85.  
  86.     switch( $method ) {
  87.       case 0:
  88.       default:
  89.         floatSliderGrp -e -en false attachCrvBlendBiasWidget;
  90.         checkBoxGrp -e -en1 false attachCrvBlendInsertWidget;
  91.         floatSliderGrp -e -en false attachCrvBlendParameterWidget;
  92.         radioButtonGrp -e -en true attachMultKnotBtn;
  93.         break;
  94.  
  95.       case 1:
  96.         floatSliderGrp -e -en true attachCrvBlendBiasWidget;
  97.         checkBoxGrp -e -en1 true attachCrvBlendInsertWidget;
  98.         floatSliderGrp -e -en $insert attachCrvBlendParameterWidget;
  99.         radioButtonGrp -e -en false attachMultKnotBtn;
  100.         break;
  101.     }
  102. }
  103.  
  104.  
  105. //
  106. //  Procedure Name:
  107. //      attachCrvSetup
  108. //
  109. //  Description:
  110. //        Update the state of the option box UI to reflect the attach
  111. //        option values.
  112. //
  113. //  Input Arguments:
  114. //      parent               - Top level parent layout of the option box UI.
  115. //                             Required so that UI object names can be 
  116. //                             successfully resolved.
  117. //
  118. //        forceFactorySettings - Whether the option values should be set to
  119. //                             default values.
  120. //
  121. //  Return Value:
  122. //      None.
  123. //
  124. global proc attachCrvSetup( string $parent,
  125.                             int $forceFactorySettings,
  126.                             string $goToTool )
  127. {
  128.     //    Retrieve the option settings
  129.     //
  130.     setOptionVars($forceFactorySettings);
  131.     attachCrvToolSetup( $forceFactorySettings, $goToTool );
  132.  
  133.     setParent $parent;
  134.  
  135.     //    Query the optionVar's and set the values into the controls.
  136.  
  137.     int $method = `optionVar -query attachCrvMethod`;
  138.     float $bias = `optionVar -query attachCrvBlendBias`;
  139.     int $insert = `optionVar -query attachCrvBlendInsert`;
  140.     float $parameter = `optionVar -query attachCrvBlendParameter`;
  141.     int $keep = `optionVar -query attachCrvKeepMultKnots`;
  142.     int $keepOrig = `optionVar -query attachCrvKeepOriginal`;
  143.  
  144.     radioButtonGrp -e -select ($method+1) attachCrvMethodWidget;
  145.     floatSliderGrp -e -v $bias attachCrvBlendBiasWidget;
  146.     checkBoxGrp -e -v1 $insert attachCrvBlendInsertWidget;
  147.     floatSliderGrp -e -v $parameter attachCrvBlendParameterWidget;
  148.     radioButtonGrp -edit -select (2 - $keep) attachMultKnotBtn;
  149.     checkBoxGrp -edit -value1 $keepOrig attachCrvKeepOriginalBox;
  150.  
  151.     if( "" != $goToTool ) { 
  152.         checkBoxGrp -e -v1 `scriptCtx -q -euc $goToTool`
  153.           scriptToolExtraWidget;
  154.         checkBoxGrp -e -v2 `scriptCtx -q -lac $goToTool`
  155.           scriptToolExtraWidget;
  156.     }
  157.  
  158.     attachCrvVisibility $parent -1 -1;
  159. }
  160.  
  161. //
  162. //  Procedure Name:
  163. //      attachCrvCallback
  164. //
  165. //  Description:
  166. //        Update the option values with the current state of the option box UI.
  167. //
  168. //  Input Arguments:
  169. //      parent - Top level parent layout of the option box UI.  Required so
  170. //               that UI object names can be successfully resolved.
  171. //
  172. //        doIt   - Whether the command should execute.
  173. //
  174. //  Return Value:
  175. //      None.
  176. //
  177. global proc attachCrvCallback( string $parent, int $doIt, string $goToTool )
  178. {
  179.     if( "" != $goToTool ) {
  180.         optionVar -iv attachCurveEuc `scriptCtx -q -euc $goToTool`;
  181.         optionVar -iv attachCurveLac `scriptCtx -q -lac $goToTool`;
  182.     }
  183.  
  184.     setParent $parent;
  185.  
  186.     //    Set the optionVar's from the control values, and then
  187.     //    perform the command.
  188.  
  189.     int $method = `radioButtonGrp -q -select attachCrvMethodWidget` - 1;
  190.     float $bias = `floatSliderGrp -q -v attachCrvBlendBiasWidget`;
  191.     int $insert = `checkBoxGrp -q -v1 attachCrvBlendInsertWidget`;
  192.     float $parameter = `floatSliderGrp -q -v attachCrvBlendParameterWidget`;
  193.     int $keep = 2 - `radioButtonGrp -query -select attachMultKnotBtn`;
  194.     int $keepOrig = `checkBoxGrp -query -value1 attachCrvKeepOriginalBox`;
  195.  
  196.     optionVar -intValue attachCrvMethod $method;
  197.     optionVar -floatValue attachCrvBlendBias $bias;
  198.     optionVar -intValue attachCrvBlendInsert $insert;
  199.     optionVar -floatValue attachCrvBlendParameter $parameter;
  200.     optionVar -intValue attachCrvKeepMultKnots $keep;
  201.     optionVar -intValue attachCrvKeepOriginal $keepOrig;
  202.         
  203.     if( 1 == $doIt ) {
  204.         performAttachCrv( 0, $goToTool ); 
  205.         string $tmpCmd = "performAttachCrv( 0, \"" + $goToTool + "\")";
  206.         addToRecentCommandQueue $tmpCmd "Attach Curves";
  207.     }
  208.     else if( $doIt ) {
  209.         setToolTo $goToTool;
  210.     }
  211. }
  212.  
  213. //
  214. //  Procedure Name:
  215. //      createAttachCrvUI
  216. //
  217. //  Description:
  218. //        Fill the contents of the option box for attach command.
  219. //
  220. //  Input Arguments:
  221. //      The name of the parent layout.
  222. //
  223. //  Return Value:
  224. //      None.
  225. //
  226. proc createAttachCrvUI(string $parent, int $inTheTool, string $goToTool)
  227. {
  228.     setParent $parent;
  229.  
  230.     radioButtonGrp -label "Attach Method"
  231.         -nrb 2
  232.         -l1 "Connect"
  233.         -l2 "Blend"
  234.         -on1 ("attachCrvVisibility " + $parent + " 0 -1" )
  235.         -on2 ("attachCrvVisibility " + $parent + " 1 -1" )
  236.         attachCrvMethodWidget;
  237.  
  238.     radioButtonGrp -label "Multiple Knots"
  239.         -numberOfRadioButtons 2
  240.         -label1 "Keep"
  241.         -label2 "Remove"
  242.         attachMultKnotBtn;
  243.  
  244.     floatSliderGrp -l "Blend Bias"
  245.         -min 0.0 -max 1.0
  246.         attachCrvBlendBiasWidget;
  247.  
  248.     checkBoxGrp
  249.         -ncb 1
  250.         -l1 "Insert Knot"
  251.         -on1 ("attachCrvVisibility " + $parent + " -1 1" )
  252.         -of1 ("attachCrvVisibility " + $parent + " -1 0" )
  253.         attachCrvBlendInsertWidget;
  254.  
  255.     floatSliderGrp -l "Insert Parameter"
  256.         -min 0.0 -max 1.0
  257.         attachCrvBlendParameterWidget;
  258.  
  259.     checkBoxGrp
  260.         -numberOfCheckBoxes 1 
  261.         -label1 "Keep Originals" 
  262.         attachCrvKeepOriginalBox;
  263.  
  264.     if( $inTheTool ) {
  265.         separator;
  266.         checkBoxGrp -ncb 2 -l "Tool Behavior"
  267.           -l1 "Exit on Completion"
  268.           -v1 off
  269.           -on1 ("scriptCtx -e -euc true " + $goToTool)
  270.           -of1 ("scriptCtx -e -euc false " + $goToTool)
  271.  
  272.           -l2 "Auto Completion"
  273.           -v2 on
  274.           -on2 ("scriptCtx -e -lac true " + $goToTool)
  275.           -of2 ("scriptCtx -e -lac false " + $goToTool)
  276.           scriptToolExtraWidget;
  277.     }
  278. }
  279.  
  280. //
  281. //  Procedure Name:
  282. //      attachOptions
  283. //
  284. //  Description:
  285. //        Construct the option box UI.  Involves accessing the standard option
  286. //        box and customizing the UI accordingly.
  287. //
  288. //  Input Arguments:
  289. //      None.
  290. //
  291. //  Return Value:
  292. //      None.
  293. //
  294. proc attachOptions( string $inTheTool, string $goToTool )
  295. {
  296.     //    Name of the command for this option box.
  297.     //
  298.     string $commandName = "attach";
  299.  
  300.     //    Build the option box actions.
  301.     //
  302.     string $callback = ($commandName + "CrvCallback");
  303.     string $setup = ($commandName + "CrvSetup");
  304.  
  305.     //  The value returned is the name of the layout to be used as
  306.     //    the parent for the option box UI.
  307.     //
  308.     global string $gOptionBoxActionToolItem;
  309.     $gOptionBoxActionToolItem = "modelWithToolAttachCurve";
  310.     global string $gOptionBoxActionToolItemCB;
  311.     $gOptionBoxActionToolItemCB = "attachCrvToolScript 3";
  312.  
  313.     string $layout = getOptionBox();
  314.     setParent $layout;
  315.     
  316.     //    Pass the command name to the option box.
  317.     //
  318.     //    Any default option box behavior based on the command name is set 
  319.     //    up with this call.
  320.     //
  321.     setOptionBoxCommandName($commandName+"Curve");
  322.  
  323.     //    Activate the default UI template so that the layout of this 
  324.     //    option box is consistent with the layout of the rest of the 
  325.     //    application.
  326.     //
  327.     setUITemplate -pushTemplate DefaultTemplate;
  328.  
  329.     //    Turn on the wait cursor.
  330.     //
  331.     waitCursor -state 1;
  332.  
  333.     //    RECOMMENDATION:  Place the UI in a scroll layout.  If the 
  334.     //    option box window is ever resized such that it's entire 
  335.     //    contents is not visible then the scroll bars provided by the
  336.     //    scroll layout will allow the user to access the hidden UI.
  337.     //
  338.     tabLayout -scr true -tv false;
  339.     
  340.     string $parent = `columnLayout -adjustableColumn 1`;
  341.  
  342.     //    Create the UI for the tab that is initially visible.
  343.     //
  344.     createAttachCrvUI($parent, $inTheTool, $goToTool);
  345.  
  346.     //    Turn off the wait cursor.
  347.     //
  348.     waitCursor -state 0;
  349.  
  350.     //    Deactivate the default UI template.
  351.     //
  352.     setUITemplate -popTemplate;
  353.  
  354.     //    Attach actions to those buttons that are applicable to the option
  355.     //    box.  Note that the 'Close' button has a default action attached 
  356.     //    to it that will hide the window.  If a a custom action is
  357.     //    attached to the 'Close' button then be sure to call the 'hide the
  358.     //    option box' procedure within the custom action so that the option
  359.     //    box is hidden properly.
  360.  
  361.     //    'Attach' button.
  362.     //
  363.     string $applyBtn = getOptionBoxApplyBtn();
  364.     if( $inTheTool ) {
  365.       button -edit -label "Attach Tool"
  366.         -command ($callback + " " + $parent + " 3 \"" + $goToTool + "\"" )
  367.         $applyBtn;
  368.     }
  369.     else {
  370.       button -edit -label "Attach"
  371.         -command ($callback + " " + $parent + " 1 \"" + $goToTool + "\"" )
  372.         $applyBtn;
  373.     }
  374.  
  375.     //    'Save' button.
  376.     //
  377.     string $saveBtn = getOptionBoxSaveBtn();
  378.     button -edit 
  379.         -command ($callback + " " + $parent + " 0 \"" +
  380.                   $goToTool + "\"; hideOptionBox")
  381.         $saveBtn;
  382.  
  383.     //    'Reset' button.
  384.     //
  385.     string $resetBtn = getOptionBoxResetBtn();
  386.     button -edit 
  387.         -command ($setup + " " + $parent + " 1 \"" + $goToTool + "\"")
  388.         $resetBtn;
  389.  
  390.     //    Set the option box title.
  391.     //
  392.     if( $inTheTool ) {
  393.         setOptionBoxTitle("Attach Curves Tool Options");
  394.     } else {
  395.         setOptionBoxTitle("Attach Curves Options");
  396.     }
  397.  
  398.     //    Customize the 'Help' menu item text.
  399.     //
  400.     setOptionBoxHelpTag( "AttachCurves" );
  401.  
  402.     //    Set the current values of the option box.
  403.     //
  404.     eval ($setup + " " + $parent + " 0 \"" + $goToTool + "\"");
  405.     
  406.     //    Show the option box.
  407.     //
  408.     showOptionBox();
  409. }
  410.  
  411. //
  412. //  Procedure Name:
  413. //      attachHelp
  414. //
  415. //  Description:
  416. //        Returns a short description about the attach command.
  417. //
  418. //  Input Arguments:
  419. //      None.
  420. //
  421. //  Return Value:
  422. //      string.
  423. //
  424. proc string attachHelp()
  425. {
  426.     return 
  427.     "  Command: Attach - joins two curves together\n" +
  428.     "Selection: two curves or a parameter point on two curves.";    
  429. }
  430.  
  431. //
  432. //  Procedure Name:
  433. //      assembleCmd
  434. //
  435. //  Description:
  436. //        Construct the attach command that will apply the option box values.
  437. //
  438. //  Input Arguments:
  439. //      None.
  440. //
  441. //  Return Value:
  442. //      The attach command string.
  443. //
  444. proc string assembleCmd()
  445. {
  446.     setOptionVars(false);
  447.  
  448.     // get the global history flag value
  449.     int $doHistory = `constructionHistory -q -tgl`;
  450.  
  451.     // is replace original on/off
  452.     int $replaceOriginal = !`optionVar -q attachCrvKeepOriginal`;
  453.     
  454.     // attach related values
  455.     int $keepMultKnots = `optionVar -query attachCrvKeepMultKnots`;
  456.  
  457.     int $method = `optionVar -query attachCrvMethod`;
  458.     float $bias = `optionVar -query attachCrvBlendBias`;
  459.     int $insert = `optionVar -query attachCrvBlendInsert`;
  460.     float $parameter = `optionVar -query attachCrvBlendParameter`;
  461.  
  462.     // set up string for preset function call
  463.     string $cmd = "doAttachCurveArgList 2 { ";
  464.  
  465.     $cmd = $cmd + "\"" + $doHistory + "\", ";
  466.     $cmd = $cmd + "\"" + $replaceOriginal + "\", ";
  467.     $cmd = $cmd + "\"" + $keepMultKnots + "\", ";
  468.     $cmd = $cmd + "\"" + $method + "\", ";
  469.     $cmd = $cmd + "\"" + $bias + "\", ";
  470.     $cmd = $cmd + "\"" + $insert + "\", ";
  471.     $cmd = $cmd + "\"" + $parameter + "\" }";
  472.  
  473.     return $cmd;
  474. }
  475.  
  476. //
  477. //  Procedure Name:
  478. //      performAttachCrv
  479. //
  480. //  Description:
  481. //        Perform the attach command using the corresponding 
  482. //        option values.  This procedure will also show the option box
  483. //        window if necessary as well as construct the command string
  484. //        that will invoke the attach command with the current
  485. //        option box values.
  486. //
  487. //  Input Arguments:
  488. //      0 - Execute the command.
  489. //      1 - Show the option box dialog.
  490. //      2 - Return the command.
  491. //      3 - Show the tool option box dialog.
  492. //
  493. //  Return Value:
  494. //      The attach command string.
  495. //
  496. global proc string performAttachCrv( int $action, string $goToTool )
  497. {
  498.     int $inTheTool = false;
  499.     if( 3 == $action ) {
  500.         $action = 1;
  501.         $inTheTool = true;
  502.     }
  503.  
  504.     string $cmd = "";
  505.     switch ($action) {
  506.       case 0:
  507.         setOptionVars(false);
  508.         $cmd = `assembleCmd`;
  509.         eval($cmd);
  510.         break;
  511.       case 1:
  512.         attachOptions( $inTheTool, $goToTool );
  513.         break;
  514.       case 2:
  515.         setOptionVars(false);
  516.         $cmd = `assembleCmd`;
  517.         break;
  518.     }
  519.     return $cmd;
  520. }
  521.